class AgentExpandUsersController{
    constructor($state,$scope,$rootScope,AccountService,AgentService) {
        Object.assign(this, {$state, $scope, $rootScope, AccountService, AgentService});
        let currentState = $state.$current.name;
        let self = this;
        this.dateFormat = "YYYY-MM-DD";
        this.start_date = moment().subtract(9, 'day').format(this.dateFormat);
        this.end_date = moment().format(this.dateFormat);
        this.daterange1 = this.start_date + ' → ' + this.end_date;
        this.userTypeList = [{value: 0, name: "直属下级"}, {value: 1, name: "全部下级"}];
        this.queryParam = {
            userType: this.userTypeList[0],
        };
        this.init();
        this.search(1);
    }

    init(){
        let self = this;
        //日期时间范围
        laydate.render({
               elem: '#expandusersForm_daterange'
               ,range: '→'
                ,value:self.daterange1
           });
    }

    /**
     * 查询
     */
    search(pageNo){
        let self  = this;
        let param = {};
        if(self.queryParam.userType){
            param.query_type =  self.queryParam.userType.value;
        }
        if(pageNo == undefined){
            pageNo = 1;
        }
        let dateRangString = $("#expandusersForm_daterange")[0].value;
        self.daterange1=dateRangString;
        if(dateRangString){
            let pieces =   dateRangString.split('→');
            let startDateStr = pieces[0].trim();
            let endDateStr = pieces[1].trim();
            if(startDateStr){
                param.start_date =startDateStr;
            }
            if(endDateStr){
                param.end_date =endDateStr;
            }
        }
        param.daterange =  self.queryParam.daterange1;
        param.page_index=pageNo;
        param.page_size=10;

        // console.log(JSON.stringify(param));
        self.AgentService.getMemberList(param).then(_success).catch(_error);
        function _success(data) {
            // if(data.success==true){
            self.resultList = data.data;
            // console.log(JSON.stringify(self.orderData));
            // }
        }
        function _error(reason) {
            console.log(JSON.stringify(reason));
            // layer.alert(reason&&reason.text?reason.text:"对不起操作失败！",{
            //     title:"错误",
            //     icon: 2,
            //     btn:["知道了"],
            //     btn1:function (index,layerro) {
            //         layer.close(index);
            //     }
            // });
        };
    }
}
AgentExpandUsersController.$inject = ["$state","$scope","$rootScope","AccountService","AgentService"];

export default AgentExpandUsersController;